home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / SOUND.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  2KB  |  67 lines

  1. ;****************************;
  2. ; WASM Sound Module          ;
  3. ; By Eric Tauck              ;
  4. ;                            ;
  5. ; Defines:                   ;
  6. ;                            ;
  7. ;   SndOn   turn speaker on  ;
  8. ;   SndOff  turn speaker off ;
  9. ;****************************;
  10.  
  11.         jmps    _sound_end
  12.  
  13. ;--- local definitions
  14.  
  15. _snd_TIMER       EQU     40H            ;8253 timer port
  16. _snd_PORTB       EQU     61H            ;8255 controller port B
  17. _snd_SBITS       EQU     00000011B      ;sound bits of port B
  18. _snd_HZDHI       EQU     0012H          ;hertz conversion constant, high word
  19. _snd_HZDLO       EQU     34DDH          ;hertz conversion constant, low word
  20.  
  21. ;========================================
  22. ; Turn on speaker.
  23. ;
  24. ; In: AX= hertz.
  25.  
  26. SndOn   PROC    NEAR
  27.  
  28. ;--- calculate frequency value
  29.  
  30.         mov     bx, ax
  31.         mov     ax, _snd_HZDLO          ;
  32.         mov     dx, _snd_HZDHI          ;load divisor
  33.         div     ax, bx                  ;get frequency value
  34.         mov     dx, ax                  ;save in DX
  35.  
  36. ;--- check sound bits
  37.  
  38.         in      al, _snd_PORTB          ;get current settings
  39.         test    al, _snd_SBITS          ;check if sound bits set
  40.         jnz     _sdon1                  ;skip if so
  41.  
  42.         or      al, _snd_SBITS          ;turn sound on
  43.         out     _snd_PORTB, al          ;send data
  44.         mov     al, 10110110B           ;select timer 2, MSB, LSB
  45.         out     _snd_TIMER+3, al        ;write timer mode
  46.  
  47. ;--- set frequency
  48.  
  49. _sdon1  mov     al, dl
  50.         out     _snd_TIMER+2, al        ;send low byte
  51.         mov     al, dh
  52.         out     _snd_TIMER+2, al        ;send high byte
  53.         ret
  54.         ENDP
  55.  
  56. ;========================================
  57. ; Turn off speaker.
  58.  
  59. SndOff  PROC   NEAR
  60.         in      al, _snd_PORTB          ;get current settings
  61.         and     al, NOT _snd_SBITS      ;clear sound bits
  62.         out     _snd_PORTB, al          ;send data
  63.         ret
  64.         ENDP
  65.  
  66. _sound_end
  67.